package proxy.myjdkproxy;


import proxy.jdkproxy.Shopping;

import java.lang.reflect.Method;

public class MyTaobao implements MyInvocationHandler{

    Shopping target;

    public Shopping getInstance(Shopping target) throws Exception {
        this.target=target;
        return (Shopping) MyProxy.newProxyInstance(new MyClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("开始前");
        //method 拼凑的目标类method
        Object res=method.invoke(target,args);
        System.out.println("开始后");
        System.out.println(res);
        return res;
    }
}
